import { 
  GET_INIT_NOTIFICATION,
  CLEAR_NOTIFICATION,
  ADD_NOTIFICATION,
} from '../constants';

const initialState = {
  notifications: 0,
  messages: 0,
};

function func(state = initialState, action) {
  switch (action.type) {
    case GET_INIT_NOTIFICATION:
      return Object.assign({}, state, {
        notifications: action.payload.notifications,
        messages: action.payload.messages,
      });

    case CLEAR_NOTIFICATION:
      if (action.payload.type == 'clear_notifications') {
        return Object.assign({}, state, {
          notifications: 0,
        });
      }
      
      if (action.payload.type == 'clear_messages') {
        return Object.assign({}, state, {
          messages: 0,
        });
      }

    case ADD_NOTIFICATION:
      if (action.payload.type == 'add_notifications') {
        return Object.assign({}, state, {
          notifications: state.notifications + 1,
        });
      }
      
      if (action.payload.type == 'add_messages') {
        return Object.assign({}, state, {
          messages: state.messages + 1,
        });
      }

    default:
      return state
  }
};

export default func;